!> 定义单例命令行参数
module sph_command_line

    use argparse, only: argparser
    private

    type, public :: command_line
        character(:), allocatable :: working_directory  !! 工作目录
        integer :: num_threads  !! 线程数
        integer :: nsteps  !! 迭代步数
    contains
        procedure :: parse => command_line_set
    end type command_line

    type(command_line), public :: cli  !! 单例命令行参数

contains

    !> 初始化和解析命令行参数
    subroutine command_line_set(self)
        class(command_line), intent(out) :: self
        type(argparser) :: args
        character(*), parameter :: version_text(*) = &
            &[character(55) :: &
            "Version    : 0.3.5, alpha (Built on "//__DATE__//')', &
#ifdef SPH_3D
            "Program    : engine(3D)", &
#else
            "Program    : engine(2D)", &
#endif
            "Description: a simulation study of hydrodynamic impact", &
            "             based on smooth particle hydrodynamics", &
            "Home Page  : https://gitee.com/fortran-sph/ti-sph", &
            "Author     : ZUO Zhihua (e-mail: zuo.zhihua@qq.com)", &
            "License    : BSD-3-Clause"]
        args = argparser("A simulation study of hydrodynamic impact &
            &based on smooth particle hydrodynamics.")
        call args%set_program_name("engine")
        call args%add_help_option()
        call args%add_sc_option('-v', '--version', 'show version info', show_version_info)
        call args%add_option_string("-C", "--directory", "working directory", ".")
        call args%add_option_integer("-t", "--num_threads", "number of OpenMP threads", 2)
        call args%add_option_integer("-n", "--nsteps", "number of time steps, \n&
            `-1` indicates that manual step input is enabled", -1)
        call args%parse()
        self%working_directory = trim(args%get_option_string("--directory"))
        self%num_threads = args%get_option_integer("--num_threads")
        self%nsteps = args%get_option_integer("--nsteps")
    contains
        !> 显示版本信息
        subroutine show_version_info()
            print '(*(a/))', version_text
        end subroutine show_version_info
    end subroutine command_line_set

end module sph_command_line
